package tpsi.pong;

import java.awt.Point;

public class Ball {
	private Point pos;
	private int vx, vy;

	public Ball() {
		this.setPos(new Point(300, 200));
		this.vx = 1;
		this.vy = 1;
	}

	public void setPos(Point pos) {
		this.pos = pos;
	}

	public Point getPos() {
		return pos;
	}

	public void setSpeed(int vx, int vy) {
		this.vx = vx;
		this.vy = vy;
	}

	public void setVX(int speed) {
		this.vx = speed;
	}

	public void setVY(int speed) {
		this.vy = speed;
	}

	public int getVX() {
		return this.vx;
	}

	public int getVY() {
		return this.vy;
	}

	/**
	 * Reverts horizontal speed vector.
	 */
	public void changeHorizontalV() {
		this.vx *= -1;
	}

	/**
	 * Reverts vertical speed vector.
	 */
	public void changeVerticalV() {
		this.vy *= -1;
	}

	/**
	 * Moves ball by V vector.
	 */
	public void move() {
		this.pos.setLocation(this.pos.getX() + this.vx, this.pos.getY()
				+ this.vy);
	}

	/**
	 * Builds and return BMOVE message with BPOS message.
	 * 
	 * @return String replay message.
	 */
	public String getBMoveMsg() {
		StringBuilder sb = new StringBuilder();
		sb.append(getBPosMsg());
		sb.append("\n");
		sb.append("BMOVE\n");
		sb.append(String.valueOf(this.vx));
		sb.append(":");
		sb.append(String.valueOf(this.vy));
		return sb.toString();
	}

	/**
	 * Builds and return BPOS message.
	 * 
	 * @return String replay message.
	 */
	private String getBPosMsg() {
		StringBuilder sb = new StringBuilder();
		sb.append("BPOS\n");
		sb.append(String.valueOf(this.pos.x));
		sb.append(":");
		sb.append(String.valueOf(this.pos.y));
		return sb.toString();
	}
}
